﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;

public partial class Products : System.Web.UI.Page
{
    public IEnumerable<Product> list;
    private CategoryManager cm = new CategoryManager();
    private ProductManager man = new ProductManager();
    private ShoppingCard card = new ShoppingCard();
    public decimal totalPrice = 0;
    public string totalQuantity = "0";
    protected void Page_Load(object sender, EventArgs e)
    {


        if (Session["cart"] != null)
        {
            BLShoppingCart cart = (BLShoppingCart)Session["cart"];
            totalPrice = cart.TotalPayment();
            totalQuantity = cart.TotalQuantity().ToString();
        }

        if (!IsPostBack)
        {
            if (Request.QueryString["cid"] != null)
            {
                int cid = Int32.Parse(Request.QueryString["cid"]);
                list = man.GetProductByCategory(cid);
                dlProduct.DataSource = list;
                dlProduct.DataBind();
            }
            else if (Request.QueryString["sid"] != null)
            {
                int sid = Int32.Parse(Request.QueryString["sid"]);
                list = man.GetProductBySupplier(sid);
                dlProduct.DataSource = list;
                dlProduct.DataBind();
            }
            else
            {
                list = man.AllProduct();
                dlProduct.DataSource = list;
                dlProduct.DataBind();
            }

            if (Request.QueryString["pr"] != null)
            {
                int nPrice = Int32.Parse(Request.QueryString["pr"]);
                if (nPrice == 1)
                {
                    list = man.SearchProductByPrice(0, 5000000);
                    dlProduct.DataSource = list;
                    dlProduct.DataBind();
                }
                else if (nPrice == 2)
                {
                    list = man.SearchProductByPrice(5000000, 10000000);
                    dlProduct.DataSource = list;
                    dlProduct.DataBind();
                }
                else if (nPrice == 3)
                {
                    list = man.SearchProductByPrice(10000000, 20000000);
                    dlProduct.DataSource = list;
                    dlProduct.DataBind();
                }
                else if (nPrice == 4)
                {
                    list = man.SearchProductByPrice(200000000, 100000000);
                    dlProduct.DataSource = list;
                    dlProduct.DataBind();
                }
                else
                {
                    list = man.AllProduct();
                    dlProduct.DataSource = list;
                    dlProduct.DataBind();
                }
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dlProduct.DataSource = man.SeachrProductByName(TextBox1.Text);
        dlProduct.DataBind();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        list = man.AllProduct();
        dlProduct.DataSource = list;
        dlProduct.DataBind();
    }
    
    
}